if ((this.info.school[0].headquarter == 1) ||(this.info.school[0].headquarter == 2)){<template>

    <d2-container type="card">





        <template slot="header">库存月报</template>
        

        <div class="d2-mb" style="display: block;width: 100%;position: relative;" >
           
            

        <!-- <el-col :span="6" style="float: right"> -->
          <el-select
            style="position: absolute;right:3vw;top:0vw;z-index: 100"
            v-model="school"
            filterable
            placeholder="所属校区"
            @change="schoolSelected"
            v-if="headquarter"
          >
            <el-option
              v-for="item in schoolList"
              :key="item._id"
              :label="item.name"
              :value="item._id"
            ></el-option>
          </el-select>

           

        </div>

        

<div style="margin-bottom: 20px;margin-top: 50px">
      
    </div>

        <el-table v-bind="table" style="width: 100%" >
            <el-table-column prop='year' label='年份'></el-table-column>
             <el-table-column  label='月份'>
                 <template slot-scope='scope'>
                     {{scope.row.month + 1}}
                 </template>
             </el-table-column>
            <el-table-column  label='操作'>
                 <template slot-scope='scope'>
                     <el-button @click='download(scope.row)' type='mini'>下载</el-button>
                 </template>
             </el-table-column>
        </el-table>
         <el-pagination
      background
      layout="total,sizes,prev, pager, next,jumper"
      :page-size="pageSize"
      :current-page="currentPage"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handlerSizeChange"
      @next-click="handleNextPage"
      @prev-click="handlePrevClick"
    ></el-pagination>

    </d2-container>
</template>

<script>
    import request from "@/plugin/axios";
        import { mapState } from "vuex";
    import excel from "@/libs/util.excel"

    function getTodayDate() {
        let day1 = new Date();
        let s1 = day1.getFullYear()+"-" + addZero(day1.getMonth()+1) + "-" + addZero(day1.getDate()) + ' ' + addZero(day1.getHours()) + ':' + addZero(day1.getMinutes()) + ':00';
        // s1 = '2019-09-21 17:00'
        return s1
    }

    function getYesterdayDate() {
        let day1 = new Date();
        day1.setDate(day1.getDate() - 1);
        let s1 = day1.getFullYear()+"-" + addZero(day1.getMonth()+1) + "-" + addZero(day1.getDate());
        return s1
    }


    function getLastMonthDate() {
        let day1 = new Date();
        day1.setMonth(day1.getMonth() - 1);
        let s1 = day1.getFullYear()+"-" + addZero(day1.getMonth()+1) + "-" + addZero(day1.getDate());
        return s1
    }

    function getLastYearDate() {
        let day1 = new Date();
        day1.setFullYear(day1.getFullYear() - 1);
        let s1 = day1.getFullYear()+"-" + addZero(day1.getMonth()+1) + "-" + addZero(day1.getDate());
        return s1
    }

    function addZero(a){
        return a < 10 ? '0' + a : a
    }

    export default {
        data() {

            return {
                filename: __filename,
                headquarter : false,
                schoolList : [],
                page : 1,
                pageSize : 20,
                display : 1,
                total : 0,
                currentPage : 1,
                table: {
                    columns: undefined,
                    data: undefined,
                    size: 'mini',
                    stripe: true,
                    border: true
                },
                filterType : [{name:'时长：日',value:'day'},{name:'时长：周',value:'week'},{name:'时长：月',value:'month'},{name:'时长：年','value':'year'}],
                                payType : [{name:'支付：不限',value:-1},{name:'支付：现金',value:0},{name:'支付：银行卡',value:1},{name:'支付：微信',value:2},{name:'支付：支付宝','value':3}],

                exportData:{
                    columns: undefined,
                    data: undefined,
                    size: 'mini',
                    stripe: true,
                    border: true
                },
                plot : {},
                queryOption:{
                    start_time:undefined,
                    end_time:undefined,
                    period : 'day',
                    payWay : -1
                },
            }
        },

                  computed:{
    ...mapState('d2admin/user',['info'])
  },


        methods: {
           
             handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      this.dataSearch.page = this.currentPage;
      this.dataSearch.pageSize = this.pageSize;
      this.getDataList(this.dataSearch);
    },
    handlerSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.dataSearch.page = this.currentPage;
      this.dataSearch.pageSize = this.pageSize;
      this.getDataList(this.dataSearch);
    },
    handleNextPage() {
      this.currentPage = this.currentPage + 1;
      this.dataSearch.page = this.currentPage;
      this.dataSearch.pageSize = this.pageSize;
      this.getDataList(this.dataSearch);
    },
    handlePrevClick() {
      this.currentPage = this.currentPage - 1;
      this.dataSearch.page = this.currentPage;
      this.dataSearch.pageSize = this.pageSize;
      this.getDataList(this.dataSearch);
    },
            formSubmit(){

                this.getInitData(this.school)
            },

            setYesterday(){

                this.queryOption.start_time = getYesterdayDate()

                this.queryOption.end_time = getTodayDate()

                this.getInitData(this.school)
            },

            setLastMonth(){

                this.queryOption.start_time = getLastMonthDate()

                this.queryOption.end_time = getTodayDate()

                this.getInitData(this.school)

            },
            setLastYear(){


                this.queryOption.start_time = getLastYearDate()

                this.queryOption.end_time = getTodayDate()

                this.getInitData(this.school)
            },


            getInitData(school) {
                let data ={}
                data.school = school
                data.page = this.page
                data.pageSize = this.pageSize


                request({
                    url: "/product/getreportlist",
                    method: "post",
                    data:data

                }).then(res => {
                    if(res.code==200){
                        
                        this.total = res.data.count
                        // this.list = res.data.data
                        this.table.columns = [{'label':'年份','prop':'year'},{'label':'月份','prop':'month'}]
                        this.table.data = res.data.data
                    }})

            },

            download(e){
                let id = e._id
                console.log(id,'aajjaj')
                request({
                    url: "/product/downloadReport",
                    method: "post",
                    data:{id:id}

                }).then(res => {
                    if(res.code==200){

                        excel.export([{'label':'商品','prop':'name'},{'label':'上月库存','prop':'lastStorage'},{'label':'本月入库','prop':'inAmount'},{'label':'本月出库','prop':'outAmount'},{'label':'本月库存','prop':'storage'}],res.data.products,res.data.year + '年' + (res.data.month + 1) + '月仓库报表'  + '(' + this.schoolname +  ')')
                       
                        
                    }})
            },


            exportExcel() {
              excel.export(this.table.columns,this.table.data,'教材收入表')
                // this.$export.excel({
                //     columns: this.table.columns,
                //     data: this.table.data,
                //     title : '教材收入表'
                // })
                //     .then(() => {
                //         this.$message('导出表格成功')
                //     })
            },
            schoolSelected() {
      // this.getDepartmentList(1, 99999);
            var ob = this.schoolList.map(function(e){return e._id}).indexOf(this.school)
            this.school = this.schoolList[ob]._id
            this.page = 1
            this.schoolname = this.schoolList[ob].name
            if (this.schoolList[ob]._id == 'all'){
                this.getInitData('all')
            }
            else{
                this.getInitData(this.schoolList[ob]._id)
            }
            
    },

    changeDisplayType() {
      // this.getDepartmentList(1, 99999);
      this.display = this.display == 0 ? 1 : 0
      this.drawLine()
    },
            getSchoolList(page, pageSize) {



      let data = {};
      (data.page = page), (data.pageSize = pageSize);
      request({
        url: "/school/getSchoolList",
        method: "post",
        data
      }).then(res => {
        console.log(res);
        // this.school = this.info.school[0]._id
        this.schoolList = []
        this.schoolList = this.schoolList.concat(res.data.school)
        // 返回数据
      });


    },
        },


        created() {


            
            this.school = this.info.school[0]._id
            this.schoolname = this.info.school[0].name
            this.getInitData(this.info.school[0]._id)
            if ((this.info.school[0].headquarter == 1) ||(this.info.school[0].headquarter == 2)){
                this.headquarter = true
                this.getSchoolList(1,99999)
            }


  }


        
}
</script>
<style lang="scss" scoped>
.page {
  .logo {
    width: 120px;
  }
  .btn-group {
    color: $color-text-placehoder;
    font-size: 12px;
    margin-top: 0px;
    margin-bottom: 20px;
    .btn-group__btn {
      color: $color-text-sub;
      &:hover {
        color: $color-text-main;
      }
      &.btn-group__btn--link {
        color: $color-primary;
      }
    }
  }
}
</style>